{%extends 'admin/layout.html'%}

{%block content%}
<div class="mdui-container-fluid">
  <div class="mdui-typo">
    <h1>系统安装 <small>Redis信息配置</small></h1>
  </div>

  <div class="mdui-row">
        <div class="mdui-col-xs-2">
            <label class="mdui-textfield-label">主机（默认localhost）</label>
            <input name="REDIS_HOST" id="REDIS_HOST" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_HOST')}}"  required="" />
        </div>
        <div class="mdui-col-xs-2">
            <label class="mdui-textfield-label">端口号（默认6379）</label>
            <input name="REDIS_PORT" id="REDIS_PORT" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_PORT')}}"  required="" />
        </div>
        <div class="mdui-col-xs-2">
            <label class="mdui-textfield-label">数据库（默认值为0）</label>
            <input name="REDIS_DB" id="REDIS_DB" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_DB')}}" required="" />
        </div>
        <div class="mdui-col-xs-2">
            <label class="mdui-textfield-label">密码（宝塔安装的默认为空）</label>
            <input name="REDIS_PASSWORD" id="REDIS_PASSWORD" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_PASSWORD')}}" />
        </div>

        <div class="mdui-col-xs-2" style="padding-top: 34px;">
            <button onclick="test_redis()" class="mdui-btn mdui-btn-block mdui-color-red-600 mdui-ripple">
              提交
            </button>
        </div>
  </div>
<hr>

</div>
<script type="text/javascript">
    function ShowNotice(msg){
        mdui.snackbar({
              message: msg,
              position: 'top'
            });
    }

    function test_redis() {
        REDIS_HOST=$("#REDIS_HOST").val();
        REDIS_PORT=$("#REDIS_PORT").val();
        REDIS_DB=$("#REDIS_DB").val();
        REDIS_PASSWORD=$("#REDIS_PASSWORD").val();
        var index2 = layer.load(2, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        $.ajax({
            type: "POST",
            url: "{{url_for('admin.test_config')}}",
            data:{soft:'redis',host:REDIS_HOST,port:REDIS_PORT,password:REDIS_PASSWORD,db:REDIS_DB},
            dataType: "json",
            success: function(data) {
                ShowNotice(data.msg);
                layer.close(index2);
                if(data.code==1){
                    window.location.href=window.location.href.replace('step=1','step=2');
                }
            }
        });

    }
</script>
{%endblock content%}
